package com.github.livebase.util;

import android.content.Context;
import android.content.ContextWrapper;

import com.github.livebase.database.LiveDatabaseHelper;
import com.github.livebase.plugins.PluginFactory;

import java.io.File;

/**
 * @ClassName LiveContext
 * @description: 在LiveContext内不允许打印日志，不允许调用打印日志的方法，因为此时未进行日志框架的初始化，日志只会调用系统的logger
 * @author: biao532
 * @create: 2023-12-30 11:12
 * @Version 1.0
 **/
public class LiveContext extends ContextWrapper {
    private LiveDatabaseHelper helper;
    private int level;
    private Object helperLock = new Object();

    private PluginFactory context;
    public LiveContext(Context base, int level) {
        super(base);
        this.level = level;
        this.context = new PluginFactory(this, level);
    }

    public LiveDatabaseHelper getLiveDatabaseHelper() {
        if (helper == null) {
            synchronized (helperLock) {
                if (helper == null) {
                    helper = new LiveDatabaseHelper(getBaseContext(), 1);
                }
            }
        }
        return helper;
    }
    public PluginFactory getPluginFactory() {
        return this.context;
    }

    public static File getLogFile(Context context, String file) {
        return new File(context.getExternalFilesDir("logs"), file);
    }
}
